<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <!--360浏览器优先以webkit内核解析-->

    <title>H+ 后台主题UI框架 - 主页示例</title>

    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="static/js/plugins/layui/css/layui.css">
    <link href="static/css/bootstrap.min.css?v=3.3.7" rel="stylesheet"/>
    <link href="static/css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="static/css/animate.css" rel="stylesheet"/>
    <link href="static/css/style.css?v=4.1.0" rel="stylesheet"/>
    <style>
        .mt-60 {
            margin-top: -60px;
        }
        .layui-table img {
            max-width: 300px
        }
        .layui-table-cell {
            height: 100px;
            line-height: 100px;
            text-align: center;
        }
        .layui-form-label{
            width: 150px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="demoTable">
                    搜索：
                    <div class="layui-inline">
                        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
                    </div>
                    <button class="layui-btn" data-type="reload" id="ss">查询</button>
                    <%--						    <button class="layui-btn" data-type="reload" id="ss2">仅查询id</button>--%>
                    <%--					        <button class="layui-btn" data-type="reload" id="ss3">仅查询用户名</button>--%>
                    <%--							<button class="layui-btn" data-type="reload" id="ss4">仅查询手机号</button>--%>
                    <%--						    <button class="layui-btn" data-type="reload" id="ss5">仅查询性别</button>--%>
                    <%--						    <button class="layui-btn" data-type="reload" id="ss6">仅查询邮箱</button>--%>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight mt-60">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="static/module/treetable-lay/treetable.js" charset="utf-8"></script>
<script src="static/module/treetable-lay/treetable.css" charset="utf-8"></script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delAll"> 批量删除</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除回复</a>
</script>
<script>
    window.name = "upd";
    layui.use(['form', 'upload', 'table', 'element', 'layer', 'laydate'], function () {
        let $ = layui.jquery
        let upload = layui.upload
        let element = layui.element
        let layer = layui.layer;
        let laydate = layui.laydate;
        let table = layui.table;
        var form = layui.form
        laydate.render({
            elem: '#grounding_date'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            , range: ['#grounding_date_from', '#grounding_date_to']
        });
//初始化时查询
            var hx = table.render({
                elem: '#test',
                height: 480,
                url: 'gly?opr=lycx',
                page: true,
                toolbar: '#toolbarDemo',
                cols: [[
                    {type: "checkbox", width: 50},
                    {field: 'id', title: '编号', sort: true,hide:true},
                    {field: 'name', title: '姓名', sort: true},
                    {field: 'phone', title: '邮箱', sort: true, width: "20%"},
                    {field: 'neirong', title: '留言内容', width: "30%",sort: true},
                    {
                        field: 'zhuangtai', title: '状态', width: "16%", sort: true, templet: function (d) {
                            var e = d.zhuangtai;
                            if (e == 0) {
                                e = '<a style="color: #00FF00">已回复</a>';
                                return e;
                            } else if (e == 1) {
                                e = '<a style="color: #ed2a4a" lay-event="jin">回复留言</a>';
                                return e;
                            }
                        }
                    },
                    {field: 'huifu', title: '回复', sort: true},
                    {title: '操作', width: "10%", toolbar: '#barDemo'}]]
            })
            table.on('toolbar(test)', function (obj) {
                switch (obj.event) {  // 监听添加操作
                    case 'delAll':
                        var checkStatus = table.checkStatus('test'),
                            data = checkStatus.data,
                            userId = "";
                        if (data.length > 0) {
                            for (var i in data) {
                                userId += data[i].id + ",";
                            }
                            console.log(userId);//打印获取到选中的id，用，分割
                            layer.confirm('确定删除选中的用户？', {icon: 3, title: '提示信息'}, function (index) {
                                $.ajax({
                                    url: "gly?opr=delly",
                                    type: "POST",
                                    data: {id: userId},
                                    success: function (msg) {
                                        if (msg == "true") {
                                            layer.msg('删除成功!', {icon: 1, time: 1000});
                                            let b=sessionStorage.obs;
                                            let a=b.replace(/\"/g, "");
                                            let cz="消息";
                                            let gn="留言批量删除";
                                            let jg="成功";
                                            $.ajax({
                                                "url": "gly?opr=xmr",
                                                "data": {name:a,cz:cz,gn:gn,jg:jg}
                                            })
                                            hx.reload({
                                                page: {
                                                    curr: 1
                                                }
                                            });
                                        } else {
                                            layer.msg('删除失败', {time: 1000});
                                            let b=sessionStorage.obs;
                                            let a=b.replace(/\"/g, "");
                                            let cz="消息";
                                            let gn="留言批量删除";
                                            let jg="失败";
                                            $.ajax({
                                                "url": "gly?opr=xmr",
                                                "data": {name:a,cz:cz,gn:gn,jg:jg}
                                            })
                                        }
                                    }
                                });
                            });
                        } else {
                            layer.msg('请选择删除的数据!', {icon: 1, time: 1000});  //如果未选择数据，则提示。
                        }
                        break;
                }
            });
        //条件查询
        $("#ss").click(function () {
            var p_name = $(".layui-input").val()
            if (p_name == null || p_name == "") {
                hx.reload({
                    url: 'gly?opr=lycx',
                    page: {
                        curr: 1
                    }
                });
            } else {
                if (p_name == "已回复" || p_name == "回复留言") {
                   hx.reload({
                        url: 'gly?opr=xxl',
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else {
                   hx.reload({
                        url: 'gly?opr=ztcxly',
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                }
            }
        })
            table.on('tool(test)', function (obj) {
                let data = obj.data;
                switch (obj.event) {
                    case 'jin':
                        layer.open({
                            title: '回复留言',
                            type: 1,
                            shade: 0.2,
                            maxmin: true,
                            shadeClose: true,
                            area: ['50%', '50%'],
                            content: $("#editForm"),
                            success: function () {
                                $("#id").val(obj.data.id);
                                $("#zhuangtai").val(obj.data.zhuangtai);
                                $("#neirong").val(obj.data.neirong);
                            }
                        })
                        layer.close(index);
                        break;
                    case'del':
                        layer.confirm('真的删除吗', function (index) {
                            $.ajax({
                                "url": "gly?opr=delly",
                                "dataType": 'text',
                                "type": 'post',
                                "data": {id: obj.data.id},
                                async: false,
                                "success": function (date) {
                                    if (date == "true") {
                                        layer.msg('删除成功', {icon: 1, time: 1500}, function () {
                                            let b=sessionStorage.obs;
                                            let a=b.replace(/\"/g, "");
                                            let cz="消息";
                                            let gn="删除留言";
                                            let jg="成功";
                                            $.ajax({
                                                "url": "gly?opr=xmr",
                                                "data": {name:a,cz:cz,gn:gn,jg:jg}
                                            })
                                            hx.reload({
                                                where: {},
                                                page: {
                                                    curr: 1
                                                }
                                            });
                                        });
                                    } else {
                                        layer.msg('删除失败', {icon: 2, time: 1500});
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="消息";
                                        let gn="删除留言";
                                        let jg="失败";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                    }
                                }
                            });
                            layer.close(index);
                        });
                        break;
                }
            });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let aa = $("#mm").val();
            if (aa==null||aa==""){
                return alert("回复内容不能为空");
            }
                let post_data = $("form").serialize();
                $.ajax({
                    "url": "gly?opr=hhh&zhi=" + aa,
                    "dataType": 'text',
                    "type": 'post',
                    "data": post_data,
                    async: false,
                    "success": function (date) {
                        if (date == "true") {
                            layer.msg('已回复', {icon: 1, time: 1500});
                                // 关闭弹出层
                                layer.closeAll();
                                let b=sessionStorage.obs;
                                let a=b.replace(/\"/g, "");
                                let cz="消息";
                                let gn="留言回复";
                                let jg="成功";
                                $.ajax({
                                    "url": "gly?opr=xmr",
                                    "data": {name:a,cz:cz,gn:gn,jg:jg}
                                })
                                hx.reload({
                                    page: {
                                        curr: 1
                                    }
                                });
                        } else {
                            layer.msg('回复失败', {icon: 2, time: 1500});
                            let b=sessionStorage.obs;
                            let a=b.replace(/\"/g, "");
                            let cz="消息";
                            let gn="留言回复";
                            let jg="失败";
                            $.ajax({
                                "url": "gly?opr=xmr",
                                "data": {name:a,cz:cz,gn:gn,jg:jg}
                            })
                        }
                    }
                })
        })
    })
</script>
<form id="editForm" method="post" style="display:none;">
    <input type="hidden" name="id" id="id">
    <input type="hidden" name="zhuangtai" id="zhuangtai">
    <input type="hidden" name="neirong" id="neirong">
<div class="layui-form-item layui-form-text">
    <label class="layui-form-label required">留言回复:</label>
    <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" type="text" lay-verify="required"
                          lay-reqtext="回复不能为空" id="mm" name="password"></textarea>
    </div>
</div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn" id="saveBtn">确认回复</button>
        </div>
    </div>
</form>
</body>

</html>